cmake_minimum_required(VERSION 3.10)
project(common_def VERSION 1.0.0)

add_library(common_def STATIC src/common_def.cpp)

# 指定公共头文件目录
target_include_directories(common_def PUBLIC 
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
)

# 安装目标及其属性
install(TARGETS common_def
        EXPORT common_defTargets
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)

# 包配置
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
    "${CMAKE_BINARY_DIR}/common_defConfigVersion.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common_defConfig.cmake.in"
    "${CMAKE_BINARY_DIR}/common_defConfig.cmake"
    INSTALL_DESTINATION lib/cmake/common_def
)

install(EXPORT common_defTargets
        FILE common_defTargets.cmake
        NAMESPACE common_def::
        DESTINATION lib/cmake/common_def)
install(FILES "${CMAKE_BINARY_DIR}/common_defConfig.cmake"
              "${CMAKE_BINARY_DIR}/common_defConfigVersion.cmake"
        DESTINATION lib/cmake/common_def)
